/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(e){
    //without overflow
    jQuery("#registerForm").validationEngine();
    
    $("#saveUser").click(function(){
        
        var studentPassword =  $("#studentPassword").val();
        var studentEmail =  $("#studentEmail").val();
        var collegeID =  $("#collegeID").val();
        var programRevisionID =  $("#programRevisionID").val();
        var studentFirstName =  $("#studentFirstName").val();
        var studentMiddleName =  $("#studentMiddleName").val();
        var studentLastName =  $("#studentLastName").val();
        var studentDateOfBirth =  $("#studentDateOfBirth").val();
        var studentPlaceOfBirth =  $("#studentPlaceOfBirth").val();
        var studentContactNo =  $("#studentContactNo").val();
        var studentAddress =  $("#studentAddress").val();
        
        if( $("#registerForm").validationEngine('validate') ){
            $.getJSON("/CBSROnline/user/register~save" ,
            {
                'studentPassword': studentPassword,
                'studentEmail' : studentEmail,
                'collegeID' : collegeID,
                'programRevisionID' :programRevisionID,
                'studentFirstName' : studentFirstName,
                'studentMiddleName' : studentMiddleName,
                'studentLastName' : studentLastName,
                'studentDateOfBirth' : studentDateOfBirth,
                'studentPlaceOfBirth' : studentPlaceOfBirth,
                'studentContactNo' : studentContactNo,
                'studentAddress':studentAddress
            },
            function(json) {
                $("#studentIDno").val(json.studentIDno);
                promptJSONMessage("#messageDialog", json);
            }
            );//end get json data 
        }
    });
//with overflow    
//    $("#registerForm").validationEngine('attach', {
//        overflownDIV:"#validationMessage",
//        isOverflown:true
//    });
//this is for menu
//this for the menu
//    $("#applicationSubMenu").show("slow").siblings().hide("slow");
//    $('#mainNavigation > li > a > span').removeClass("main-menu-highlight");
//    $("#applicationMenu > span").addClass("main-menu-highlight");
//    $('.gen-menu-ul > li > a > span').removeClass("sub-menu-highlight");
//    $(".gen-menu-ul > li > a > #loanApplication").addClass("sub-menu-highlight");
//    //end of menu
//    $("#saveLoanButton").click(function(){
//        if( $("#loanApplicationForm").validationEngine('validate') ){
//            $.ajax({
//                type: "POST",
//                url: "/cashmatecreditcorporation/loan application/save",
//                data: $("#loanApplicationForm").serialize(), // serializes the form's elements.
//                success: function(data)
//                {
//                    promptJSONMessage("#loanApplicationDialog", data);
//                }
//            });
//        }
//        
//    });//save loan button
//    
//    $("#newLoanButton").click(function(){
//        //        clearForm("#loanApplicationForm");
//        //        window.location="create-loan-application";
//        $.getJSON("/cashmatecreditcorporation/loan application/create" ,
//        {
//            //                'borrower.borrowerId': borrowerId
//            },
//            function(json) {
//                promptJSONMessage("#loanApplicationDialog", json);
//                $("#documentNumber").val(json.documentNumber);
//                $("#documentDate").val(json.documentDate);
//            }
//            ); 
//    });//create loan button
//    
//    $("#addDependentsButton").click(function(){
//        if($("#dependentsTable tr").length <= 5){
//            cloneTableRow("dependentsTable"); 
//        }
//        
//    });//add dependent button
//    
//    $("#dependentsTable tr td span.gen-delete-icon").click(function(){
//        //        alert("Praise God");
//        if($("#dependentsTable tr").length > 2){
//            var row = $(this).parent().parent();
//            var relativeId = $('#relativeId', $(this).parent()).val();
//            
//            if(relativeId > 0){
//                $.getJSON("/cashmatecreditcorporation/relative/delete~id" ,
//                {
//                    'borrowersRelative.relativeId': relativeId
//                },
//                function(json) {
//                    promptJSONMessage("#loanApplicationDialog", json);
//                    if(json.result > 0){
//                        row.remove();
//                    }
//                }
//                );//end get json data 
//            }else{
//                row.remove();
//            }
//            
//        }
//    });//delete row dependent button
//    
//    $("#addLoansButton").click(function(){
//        if($("#otherLoansTable tr").length <= 5){
//            cloneTableRow("otherLoansTable");   
//        }
//        
//    });//add dependent button
//    $("#otherLoansTable tr td span.gen-delete-icon").click(function(){
//        var row = $(this).parent().parent();
//        var otherLoansId = $('#otherLoansId', $(this).parent()).val();
//            
//        if(otherLoansId > 0){
//            $.getJSON("/cashmatecreditcorporation/other loans/delete~id" ,
//            {
//                'otherLoans.otherLoansId': otherLoansId
//            },
//            function(json) {
//                promptJSONMessage("#loanApplicationDialog", json);
//                if(json.result > 0){
//                    row.remove();
//                }
//            }
//            );//end get json data 
//        }else{
//            row.remove();
//        }
//    });//delete row loans button
    
});//end of document ready


